package tech.senri.iot.socket.model

import io.netty.buffer.Unpooled
import io.swagger.annotations.ApiModelProperty
import tech.senri.iot.socket.service.util.getArray

class UpdatePriceInventoryRequest : RequestMessage()
{
    @ApiModelProperty("货道数量", required = true)
    var aisleCount: Int = 0

    @ApiModelProperty("商品库存,数组形式对应每个货道", required = true)
    var inventory: IntArray? = null

    @ApiModelProperty("商品价格，数组形式对应每个货道", required = true)
    var prices: IntArray? = null


    override fun contentData(): ByteArray
    {
        val buffer = Unpooled.buffer()
        /**
         * 货道数量
         */
        buffer.writeByte(aisleCount)
        /**
         * 商品库 存
         */
        inventory?.let {
            for (i in 0 until it.size)
            {
                buffer.writeByte(it[i])
            }
        }

        /**
         * 商品价 格
         */
        prices?.let {
            for (i in 0 until it.size)
            {
                buffer.writeShort(it[i])
            }
        }
        /**
         * 机器类型
         */
        buffer.writeByte(0x01)
        /**
         * 备用
         */
        buffer.writeBytes(byteArrayOf(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00))
        return buffer.getArray()
    }
}
